/*
 * JSR.c
 *
 *  Created on: Jan 20, 2014
 *      Author: adijoshi
 */

#include "includes.h"

/*
 * Function: func_JSR
 *
 * Inputs:	 Mnemonic, Address_of_source, Address_of_destination
 * Outputs:  Result

Condition Codes: None affected.

Description:
				dst -> (tmp)
				(reg) pushed on stack
				(PC) -> (reg)
				(tmp) -> (PC)

the  old contents  of  the  specified-register, are  pushed  onto  the  processor  stack
and  new  linkage  information  placed  in  the  register.
*/

unsigned short func_JSR(unsigned short register_address,unsigned short destination_address)
{
	unsigned short register_data;
	unsigned short prog_counter;
	//unsigned short destination_data;

	register_data = read_from_memory(register_address, DATA);
	push(register_data);

	prog_counter = get_Program_Counter();

	write_in_memory(register_address, prog_counter, DATA);

	//destination_data = read_from_memory(destination_address, DATA);
	set_Program_Counter(destination_address);
	return destination_address;
}
